
package ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.view.View;

import net.ck.hzq.R;

import java.util.ArrayList;
import java.util.List;

import base.BaseViewHolder;
import base.SuperBaseAdapter;
import ui.model.SearchInfoBean;


/**
 *POS查询列表适配器
 * Created by chenjian on 19/2/27
 */
public class SearchInfoAdapter extends SuperBaseAdapter<SearchInfoBean> {

    List<SearchInfoBean> mData = new ArrayList<>();
    Context mContext;
    String mcontent="";
    int mactiveStatus = 0;
    public SearchInfoAdapter(Context context, List<SearchInfoBean> data) {
        super(context, data);
        mContext = context;
        mData = data;
    }

    @Override
    protected void convert(BaseViewHolder holder, final SearchInfoBean item, final int position) {
        holder.setText(R.id.question_txt, item.getContent());

        if(item.getContent().contains(mcontent)){
            holder.setText(R.id.question_txt, setColor(mContext,item.getContent(),mcontent));
        }else{
            holder.setText(R.id.question_txt, item.getContent());
        }
        holder.getView(R.id.question_txt).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext,item.getCls());
                    mContext.startActivity(intent);

            }
        });

    }
    public static CharSequence setColor(Context context, String text, String text1) {
        int tag = text.indexOf(text1);
        SpannableStringBuilder style = new SpannableStringBuilder(text);
// 关键字“孤舟”变色，0-text1.length()
        style.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.red_fe3333)), tag,tag + text1.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return style;
    }
    public void setupData(List<SearchInfoBean> learnQueslists, String content) {
        if (mData != null) {
            mData = learnQueslists;
        }
        mcontent = content;
        notifyDataSetChanged();
    }

    @Override
    protected int getItemViewLayoutId(int position, SearchInfoBean item) {
        return R.layout.item_searchinfo_list;
    }

}
